#! user/bin/python
# -*- coding: utf-8 -*-

"""
Created on 2021/8/25 9:00

@File: 初步使用urllib下载文件_getone-urllib.py
@Author: LT
@Description: Use of this module
"""
import os, getpass
import urllib.request
from urllib.request import urlopen                                              # 基于套接字的网络工具

filename = 'monkeys.jpg'                                                        # 远程/本地文件名
password = getpass.getpass("Pswd?")

remoteaddr = 'ftp://lutz:%s@ftp.rmi.net/%s;type=i' % (password, filename)
print("Downloading", remoteaddr)

# 也可以用下面这个语句
# urllib.request.urlretrieve(remoteaddr, filename)

remotefile = urlopen(remoteaddr)
localfile = open(filename, "wb")
localfile.write(remotefile.read())
localfile.close()
remotefile.close()
